import { PageParam } from '@/services/common'
import { GenerateColumnUpdateDTO } from '@/services/GenerateColumnService'
import { covertTableData } from '@/utils/tableUtil'
import { request } from '@umijs/max'

export interface GenerateTableVO {
  id: string
  /**
   * 业务注释
   */
  businessComment?: string
  /**
   * 业务名
   */
  businessName?: string
  /**
   * 表名
   */
  tableName?: string
  /**
   * 包名
   */
  package?: string
}

export interface GenerateTableQueryDTO extends PageParam {
  /**
   * id
   */
  id?: string
  /**
   * 业务注释
   */
  businessComment?: string
  /**
   * 业务名
   */
  businessName?: string
  /**
   * 表名
   */
  tableName?: string
  /**
   * 包名
   */
  package?: string
}

export interface GenerateTableUpdateDTO {
  /**
   * 业务注释
   */
  businessComment?: string
  /**
   * 业务名
   */
  businessName?: string
  /**
   * 表名
   */
  tableName?: string
  /**
   * 包名
   */
  package?: string
  columns?: GenerateColumnUpdateDTO[]
}

export const getGenerateTableById = async (id: string) => {
  return request<GenerateTableVO>(`/api/generateTable?id=${id}`, { method: 'GET' })
}

export const getGenerateTableList = async (params: GenerateTableQueryDTO) => {
  return request<Array<GenerateTableVO>>(`/api/generateTable/list`, { method: 'GET', params })
}

export const getGenerateTablePage = async (params: GenerateTableQueryDTO) => {
  let response = await request<Array<GenerateTableVO>>(`/api/generateTable/page`, { method: 'GET', params })
  return covertTableData(response)
}

export const updateGenerateTable = async (generateTableUpdateDTO: GenerateTableUpdateDTO) => {
  return request<GenerateTableVO>(`/api/generateTable/update`, { method: 'POST', data: generateTableUpdateDTO })
}

export const saveGenerateTable = async (generateTableUpdateDTO: GenerateTableUpdateDTO) => {
  return request<GenerateTableVO>(`/api/generateTable/save`, { method: 'POST', data: generateTableUpdateDTO })
}

export const removeGenerateTable = async (id: string) => {
  return request<boolean>(`/api/generateTable/remove?id=${id}`, { method: 'POST' })
}
